package com.zhang.simple.chatgpt;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import lombok.extern.slf4j.Slf4j;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2024-02-27 16:07
 **/
@Slf4j
public class WebSocketOutboundHandler extends ChannelOutboundHandlerAdapter {

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {

        // 做加密等
        log.info("服务端向客户端主动发送消息:{}",msg);
        ctx.write(msg, promise);
        ctx.flush();
        // 传递给下一个处理器，实际上没有作用，反而报错
//        super.write(ctx, msg, promise);
    }
}
